package com.bws;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class HBaseDemo {

  Configuration conf=null;
  Connection conn=null;
  //表管理对象
  Admin admin=null;
  //创建表对象
  TableName tableName=TableName.valueOf("phone");

  @Before
  public void init() throws IOException {
    //创建配置文件对象
    conf= HBaseConfiguration.create();
    //加载zk
    conf.set("hbase.zookeeper.quorum","192.168.79.7");
    //获取链接
    conn= ConnectionFactory.createConnection(conf);
    //获取对象
    admin = conn.getAdmin();
   // HTable desc=new HTable(conf,tableName);
  }
  @Test
  public void createTable() throws IOException {
    HTableDescriptor table=new HTableDescriptor(TableName.valueOf("tableName"));
    table.addFamily(new HColumnDescriptor("cf".getBytes()));
/*
    if(admin.tableExists(table.getTableName())){
      admin.disableTable(table.getTableName());
      admin.deleteTable(table.getTableName());
    }*/

    admin.createTable(table);

  }

}
